package com.cxc.minio.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxc.minio.entity.UserContract;
import com.cxc.minio.entity.UserImage;
import com.cxc.minio.service.UserContractService;
import com.cxc.minio.mapper.UserContractMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author cxc
* @description 针对表【t_user_contract】的数据库操作Service实现
* @createDate 2025-01-04 16:42:28
*/
@Service
public class UserContractServiceImpl extends ServiceImpl<UserContractMapper, UserContract>
    implements UserContractService{

    @Resource
   private UserContractMapper userContractMapper;

    @Override
    public boolean saveOrUpdate(Integer uid, String bucketName, String objectName) {
        LambdaQueryWrapper<UserContract> wrapper = new LambdaQueryWrapper<UserContract>()
                .eq(UserContract::getUid,uid);
        long count = userContractMapper.selectCount(wrapper);
        boolean flag = false;
        UserContract userContract = new UserContract();
        userContract.setBucket(bucketName);
        userContract.setObject(objectName);
        userContract.setUid(uid);
        if (count<=0){
            userContract.setCreateTime(new java.util.Date());
            flag = userContractMapper.insert(userContract)>=1;
        }else {
            userContract.setUpdateTime(new java.util.Date());
            flag = userContractMapper.update(userContract,wrapper)>=1;
        }
        return flag;
    }
}




